from django.db import models
from datetime import datetime

# 基类


class Base(models.Model):
    id = models.AutoField(primary_key=True)

    class Meta:
        # 可继承
        abstract = True


# 用户表
class User(Base):

    username = models.CharField(max_length=20)
    password = models.CharField(max_length=120)
    img = models.CharField(max_length=200)
    video = models.CharField(max_length=200, default='')
    # 用户类型 0普通用户 1管理员 2商家
    typ = models.IntegerField(default=0)

    class Meta:
        db_table = "user"


# 商品表
class Goods(Base):
    # 商品名称
    name = models.CharField(max_length=120)
    # 商品描述
    desc = models.CharField(max_length=500)
    # 商品头图
    img = models.CharField(max_length=200)
    # 商品类别
    cid = models.IntegerField()
    # 商品规格
    param = models.CharField(max_length=500)
    # 演示视频
    video = models.CharField(max_length=200)
    # 关注
    flow = models.IntegerField(default=0, null=True)
    # 价格(分)
    price = models.IntegerField()

    class Meta:
        db_table = 'goods'


# 商品分类表
class Category(Base):
    cname = models.CharField(max_length=200)

    class Meta:
        db_table = 'category'


# 幻灯片表
class Pics(Base):
    # 名称
    title = models.CharField(max_length=120)
    # 链接
    link = models.CharField(max_length=200)
    # 图片
    image = models.CharField(max_length=200)

    class Meta:
        db_table = "pics"


# 用户评论表
class Comment(Base):
    # 评论内容
    content = models.CharField(max_length=120)
    # 评论人
    uid = models.CharField(max_length=50)
    # 评论对应商品
    gid = models.IntegerField()

    # 表名
    class Meta:
        db_table = 'comment'


# 关注表
class UserFlow(Base):
    # 谁关注的
    uid = models.IntegerField()
    # 关注的商品
    gid = models.IntegerField()

    class Meta:
        db_table = 'userflow'
